let OSS = require('ali-oss');
let config = require('../../../../config')
let client = new OSS({
  accessKeyId: 'LTAIKqa4XUOwajiT',
  accessKeySecret: '7ycL9N1EJ5MdcF9FdT0jzepj5rgZ3d',
  timeout: 600000
})
client.useBucket(config.bucket);
module.exports = class extends think.Controller {
  async indexAction () { // 检查版本
    console.log(this.file('file').path)
    try {
      let result = await client.put(this.post().objname, this.file('file').path);
      console.log(result)
      if (result.res.statusCode === 200) {
        this.json({
          status: 1,
          url: '/getOssFile/?objname=' + this.post().objname
        })
      } else {
        throw new Error('文件上传OSS出错')
      }
    } catch (err) {
      this.ctx.fail( 1001, err.message)
    }
  }
}